﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils.Menu;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.Base;

namespace ERP_RORZE_PRODUCT.Product.MO
{
    public partial class ctrlMOQtyStatus : DevExpress.XtraEditors.XtraUserControl
    {
        ClsMODAO clsMODAO = new ClsMODAO();
        DataTable dt;
        DXPopupMenu menu;
        private int range = 1;

        public ctrlMOQtyStatus()
        {
            InitializeComponent();

            InitDateRangeMenu();
            this.dropbtDateRange.DropDownControl = menu;
            this.dropbtDateRange.Text = "3 Months";
        }

        private void ctrlMOQtyStatus_Load(object sender, EventArgs e)
        {
            BindDatatoGrid(range);
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            ctrlMOQtyStatus_Load(sender, e);
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            clsConstantsFuction.ExportToExcel(gridView1, 1, true);
        }

        //Date range
        protected virtual void InitDateRangeMenu()
        {
            menu = new DXPopupMenu();
            menu.Items.Add(new DXMenuItem("3 Months", new EventHandler(OnItemClick3Month), null, null, null, null));
            menu.Items.Add(new DXMenuItem("6 Months", new EventHandler(OnItemClick6Months), null, null, null, null));
            menu.Items.Add(new DXMenuItem("One Year", new EventHandler(OnItemClick1Year), null, null, null, null));
            menu.Items.Add(new DXMenuItem("All time", new EventHandler(OnItemClickAllTime), null, null, null, null));

        }

        void OnItemClick3Month(object sender, EventArgs e)
        {
            BindDatatoGrid(1);
            range = 1;
            dropbtDateRange.Text = "3 Months";
        }

        void OnItemClick6Months(object sender, EventArgs e)
        {
            BindDatatoGrid(2);
            range = 2;
            dropbtDateRange.Text = "6 Months";
        }

        void OnItemClick1Year(object sender, EventArgs e)
        {
            BindDatatoGrid(3);
            range = 3;
            dropbtDateRange.Text = "One Year";
        }

        void OnItemClickAllTime(object sender, EventArgs e)
        {
            BindDatatoGrid(0);
            range = 0;
            dropbtDateRange.Text = "All time";
        }

        private void BindDatatoGrid(int range = 1)
        {
            Cursor.Current = Cursors.WaitCursor;
            dt = clsMODAO.MOQtyStatusRange(range);
            gridControl1.DataSource = dt;
            gridView1.BestFitColumns();

            Cursor.Current = Cursors.Default;

        }
    }
}
